<template>
	<view class="content">
		<view class="user-list">
			<view class="user-item" v-for="(item,index) in userList" :key="index">
				<view class="user-box flexWrap">
					<view class="user-info-box flexWrapNo">
						<image :src="item.avatar" class="head-img"></image>
						<view class="user-info">
							<view>{{item.nickname}}</view>
							<view>{{item.mobile}} <text style="margin-left: 30upx;color: #26BCFD;" @tap="copy(item.mobile)">复制</text></view>
						</view>
					</view>
					<view>加入时长：{{item.jointime}}</view>
				</view>
				<view class="data-box flexWrap">
					<view class="data-item flexWarpCenterColumn">
						<text>￥{{item.total_money}}</text>
						<text class="data-text">总消费</text>
					</view>
					<view class="data-item flexWarpCenterColumn">
						<text>{{item.count}}小时</text>
						<text class="data-text">总时长</text>
					</view>
					<view class="data-item flexWarpCenterColumn">
						<text>{{item.coupon}}</text>
						<text class="data-text">优惠券</text>
					</view>
					<view class="data-item flexWarpCenterColumn">
						<text>￥{{item.recharge}}</text>
						<text class="data-text">充值总额</text>
					</view>
					<view class="data-item flexWarpCenterColumn">
						<text>￥{{item.money}}</text>
						<text class="data-text">余额总额</text>
					</view>
				</view>
			</view>
			<uni-load-more v-if="showLoadStatus" :status="status" :size="14" :content-text="contentText" />
			<view class="empty-box" v-if="showEmpty">
				<image src="https://static.mo-yu.vip/wechat/images/orderEmpty.png"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				//下拉刷新
				page: 1,
				size:10,
				showEmpty: true,
				showLoadStatus: false,
				more: true,
				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中...',
					contentnomore: '已经到底了~~'
				},
				status: 'loading',
				userList:[],
				task_id:""
			};
		},
		// 下拉刷新
		onPullDownRefresh: function() {
			this.freshList();
			this.$tools.loadIng()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 500)
		},
		onLoad(ops) {
			this.task_id=ops.taskId
			this.getData();
		},
		methods:{
			copy(mobile){
				let that = this
				uni.setClipboardData({
					data:mobile,
					success: function() {
						console.log('success');
					}
				});
			},
			// 刷新列表
			freshList() {
				this.page = 1
				this.more = true
				this.status = 'loading'
				this.userList = []
				this.getData();
			},
			// 获取列表
			getData(){
				let self=this
				this.$request.post(this.$api.challengeSuccessList, {
					page:this.page++,
					num:this.size,
					store_id:uni.getStorageSync('store_id'),
					task_id:this.task_id
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						let newArray =data
						if (newArray.length == 0 && self.page == 2) {
							self.showEmpty = true
							self.showLoadStatus = false
							self.more = false // 不能再次请求了
							return false;
						} else {
							self.showLoadStatus = true
							self.more = true
							self.showEmpty = false
							self.status = 'loading'
						}
						if (newArray.length < this.size) { // 说明没有更多数据
							self.status = 'noMore'
							self.more = false
							self.showEmpty = false
						}
						self.userList=self.userList.concat(newArray);
					}
				}).finally(() => {
					setTimeout(()=>{
						this.$tools.hideLoading()
					}, 1000)
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		padding-bottom: 120upx;
	}
	.content{
		padding: 36upx;
	}
	.user-item{
		background: #1D1C5C;
		border-radius: 16rpx;
		padding:32upx 28upx;
		margin-bottom: 30upx;
		.user-box{
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 60upx;
			color: #FFFFFF;
			.user-info-box{
				.head-img{
					width: 100upx;
					height: 100upx;
					border: 1rpx solid #FFFFFF;
					border-radius: 50%;
					overflow: hidden;
					margin-right: 20upx;
				}
			}
		}
		.data-box{
			padding-top: 20upx;
			margin-top: 20upx;
			border-top: 1rpx solid #FFF;
			flex-wrap: wrap;
			.data-item{
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				.data-text{
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #8E8EAE;
					margin-top: 10upx;
				}
			}
		}
	}
	.empty-box{
		margin: 64upx auto;
		width: 476upx;
		height: 280upx;
	}
</style>
